package com.yixun.lbx.controller.informationManagement;

import com.yixun.controller.BaseController;
import com.yixun.lbx.entity.YxProLegalInfo;
import com.yixun.lbx.service.LegalInfoServie;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/li")
public class LegalInfoController extends BaseController {
    private final LegalInfoServie legalInfoServie;

    public LegalInfoController(LegalInfoServie legalInfoServie) {
        this.legalInfoServie = legalInfoServie;
    }

    /*
     *获取法律法规列表
     */
    @PostMapping("/getListByPage")
    public HashMap<String, Object> getListByPage(@RequestBody HashMap<String, Object> map) {
        Integer count = legalInfoServie.getCount(map);
        List<YxProLegalInfo> legalInfos = legalInfoServie.getListByPage(map);
        map.put("count", count);
        map.put("legalInfos", legalInfos);
        return map;
    }

    /*
     *获取法律法规列表
     */
    @PostMapping("/farm_getListByPage")
    public HashMap<String, Object> farm_getListByPage(@RequestBody HashMap<String, Object> map) {
        Integer count = legalInfoServie.getCount(map);
        List<YxProLegalInfo> legalInfos = legalInfoServie.farm_getListByPage(map);
        map.put("count", count);
        map.put("legalInfos", legalInfos);
        return map;
    }

    /*
     *添加法律法规
     */
    @PostMapping("/addLegalInfo")
    public int addLegalInfo(@RequestBody HashMap<String, Object> map) {
        map.put("addUser", this.getSessionUser().getUser_id());
        return legalInfoServie.addLegalInfo(map);
    }

    /*
     *修改法律法规
     */
    @PostMapping("/updateLegalInfo")
    public int updateLegalInfo(@RequestBody HashMap<String, Object> map) {
        map.put("updateUser", this.getSessionUser().getUser_id());
        return legalInfoServie.updateLegalInfo(map);
    }

    /*
     *删除法律法规
     */
    @PostMapping("/deleteLegalInfo")
    public int deleteLegalInfo(@RequestBody HashMap<String, Object> map) {
        map.put("updateUser", this.getSessionUser().getUser_id());
        String[] ids = map.get("id").toString().split(",");
        map.put("ids", ids);
        return legalInfoServie.deleteLegalInfo(map);
    }

    @GetMapping("/getObjByArgs")
    public List<YxProLegalInfo> getObjByArgs(YxProLegalInfo legalInfo) {
        return legalInfoServie.getObjByArgs(legalInfo);
    }

    /*搜索*/
    @RequestMapping("/getSearchListByPage")
    public HashMap<String, Object> getSearchListByPage(@RequestBody HashMap<String, String> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        List<YxProLegalInfo> obj = legalInfoServie.getSearchListByPage(map);
        hashMap.put("obj", obj);
        hashMap.put("count", obj.size());
        return hashMap;
    }

    @GetMapping("/getShowList")
    public List<YxProLegalInfo> getShowList() {
        return legalInfoServie.getShowList();
    }
}
